Skip to content

nmc: P1 PD embedded AuxChainEmbedded (dual-target + parent-coinbase commitment) - #214

Merged
frstrtr merged 3 commits into
masterfrom
nmc/p1-pd-auxpow-dualtarget
Jun 19, 2026
Merged

nmc: P1 PD embedded AuxChainEmbedded (dual-target + parent-coinbase commitment)#214
frstrtr merged 3 commits into
masterfrom
nmc/p1-pd-auxpow-dualtarget

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Stacked on #213 (PC). Phase PD of the embedded merge-mined Namecoin lane.

What

Implements c2pool::merged::IAuxChainBackend (nmc::coin::AuxChainEmbedded) over the embedded NMC HeaderChain + TemplateBuilder — the build-side complement of the P1c/P1d/P1f verify legs. Analog of src/impl/doge/coin/aux_chain_embedded.hpp, adapted to the BTC parent (SHA256d) and NMCChainParams::aux_chain_id.

get_work_template() surfaces:

  • dual-target — the aux PoW target derived from template bits (a found share is a real NMC block only when parent-PoW <= this target);
  • the NMC block-hash committed in the parent BTC coinbase (the aux-merkle leaf the verifier later proves via aux_merkle_root());
  • chain_id from NMCChainParams::aux_chain_id (the same consensus field the verify side pins, not the transport-layer config copy);
  • a sync gate: empty/stale chain -> empty work (no daemon, no stale-tip leak).

Plus submit_block (P2P-relay, embedded) + submit_aux_block fallback (logged; no daemon to RPC).

Tests

+4 KATs into the existing nmc_template_builder_test exe (10 -> 14 green, exit 0): dual-target independent re-derivation, parent-coinbase commitment == tip, sync gate, createauxblock==getblocktemplate, submit/get_block_hex cache.

Fence

src/impl/nmc/ only; btc tree consumed READ-ONLY; merged_mining seam consumed READ-ONLY. No core/ and no build.yml change — rides the existing test exe (no new NOT_BUILT allowlist entry).

Caveat (carried from P1f)

aux_chain_id / auxpow_activation_height remain unpinned (-1 sentinel) in production params; the KATs use a TEST-only pin (1 / 19200). Pinning against a live namecoind is the open P1f blocker on integrator.

frstrtr added 3 commits June 19, 2026 14:10
Adds nmc::coin::Mempool — a byte-faithful mirror of src/impl/btc/coin/
mempool.hpp re-homed into namespace nmc::coin so the NMC coin tree stays
self-contained (no btc::coin symbols). Namecoin is a Bitcoin fork: same
wire format, 21M money cap, 100-block coinbase maturity (NMC_LIMITS,
instantiated locally from the public core::coin::ChainLimits; no core
edit). Feeds the P1 PC template builder next.

Coverage: +3 KATs in the existing (CI-allowlisted) nmc_auxpow_merkle_test
(add/contains/remove + dedup, feerate-ordered selection, confirmed-block
cleanup). Suite 66 -> 69 green. Fence held: src/impl/nmc/ only, no
build.yml / src/core / bitcoin_family change.

Reference: namecoin-core (Bitcoin fork) txmempool.cpp / amount.h MAX_MONEY,
consensus.h COINBASE_MATURITY.
Re-home the BTC native block-template builder into the NMC coin tree so the
embedded merge-mined Namecoin chain can build block templates (WorkData)
natively from its HeaderChain + Mempool, without the getblocktemplate RPC.

  * coin/rpc_data.hpp        -- nmc::coin::rpc::WorkData (template payload)
  * coin/template_builder.hpp -- get_block_subsidy (50 NMC, halving every
    210,000 blocks, identical to Bitcoin), compute_merkle_root (SHA256d),
    CoinNodeInterface, TemplateBuilder::build_template, EmbeddedCoinNode;
    log tags [EMB-NMC].
  * coin/header_chain.hpp    -- add get_header_by_height (parent-link walk,
    no height index), is_synced (DEFAULT_MAX_TIP_AGE gate), and the
    get_next_work_required / calculate_next_work_required retarget the
    builder needs. NMC shares Bitcoins 2016-block / 10-minute retarget.
  * coin/coin_smoke.cpp + CMakeLists -- force-compile the header-only builder.

PC is the STRUCTURAL builder only; merge-mining commitment / dual-target
(phase PD) are not implemented here.

KATs: nmc_template_builder_test (10) covers subsidy halving boundaries,
compute_merkle_root (0/1/2/odd/even leaves, independently re-derived), and
build_template on a seeded chain (tip -> WorkData; empty -> nullopt).
Suite 69 -> 79 green. Fenced to src/impl/nmc/ (plus the one build.yml
--target allowlist line). btc/core trees consumed READ-ONLY.
…ommitment)

Implements c2pool::merged::IAuxChainBackend over the embedded NMC
HeaderChain + TemplateBuilder (analog of doge aux_chain_embedded.hpp,
adapted to the BTC parent / SHA256d / NMCChainParams::aux_chain_id).

Build-side complement of the P1c/P1d/P1f verify legs:
  * get_work_template() surfaces the aux PoW target (dual-target check)
    and the NMC block-hash committed in the parent BTC coinbase;
  * chain_id sourced from NMCChainParams::aux_chain_id (the same field
    the verify side pins), not the transport-layer config copy;
  * sync gate: empty/stale chain yields empty work (no daemon, no leak);
  * submit_block P2P-relay path + submit_aux_block fallback (logged).

+4 KATs into the existing nmc_template_builder_test exe (10->14 green):
dual-target re-derivation, parent-coinbase commitment == tip, sync gate,
createauxblock==getblocktemplate, submit/get_block_hex cache.

Fence: src/impl/nmc/ only; btc tree READ-ONLY; merged_mining seam
consumed READ-ONLY. No core/ or build.yml change (rides existing exe).
@frstrtr
frstrtr changed the base branch from nmc/p1-pc-template-builder to master June 19, 2026 14:58
@frstrtr frstrtr closed this Jun 19, 2026
@frstrtr frstrtr reopened this Jun 19, 2026
@frstrtr
frstrtr merged commit 15f21a7 into master Jun 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant